package www.m01.springcloud.controller;

import javax.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;
import www.m01.springcloud.domains.Payment;
import www.m01.springcloud.domains.Rs;

/**
 * PaymentController
 *
 * @author hyr
 * @date 2022/7/8
 */
@Slf4j
@RestController
@RequestMapping("/order")
public class OrderController {

    public static final String PAYMENT_URL = "http://PAYMENT-SERVICE";

    @Resource
    private RestTemplate restTemplate;

    @PostMapping("/consumer/create")
    public Rs<Integer> create(Payment payment) {
        return restTemplate.postForObject(PAYMENT_URL + "/payment/create", payment, Rs.class);
    }

    @GetMapping("/consumer/get/{id}")
    public Rs<Payment> getPayment(@PathVariable("id") Long id) {
        return restTemplate.getForObject(PAYMENT_URL + "/payment/get/" + id, Rs.class);
    }

}
